package ee.nlp.evn.tools;

public class Tokenizer {
	public static String getFirstToken(String s) {
		String result = "";
		if (!s.isEmpty()) {
			try {
				int i = 0;
				while (Character.isWhitespace(s.charAt(i)) && i < s.length())
					i++; // skip empty space
				if (Character.isDigit(s.charAt(i))) {
					result = String.valueOf(s.charAt(i++));
					while (i < s.length() && Character.isDigit(s.charAt(i))) {
						result += String.valueOf(s.charAt(i++));
					}
				} else if (Character.isLetter(s.charAt(i))) {
					result = String.valueOf(s.charAt(i++));
					while (i < s.length() && Character.isLetterOrDigit(s.charAt(i))) {
						result += String.valueOf(s.charAt(i++));
					}
				} else {
					result = String.valueOf(s.charAt(i));
				}
			} catch (Exception e) {
				System.err.println("Line: " + s);
				e.printStackTrace();
			}
		}
		return result;
	}

}
